package com.guchenbo.example.lock;

import java.util.HashMap;
import java.util.UUID;

/**
 * Created by CreGu on 2016/6/20.
 */
public class TestHashMap {

    /**
     * hashmap的线程安全测试
     */
    public void hashMap1(){
        final HashMap<String, String> map = new HashMap<String, String>(2);
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {

                for (int i=0;i<10000;i++) {
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            map.put(UUID.randomUUID().toString(), "");
                        }
                    },"ftf"+i).start();
                }
            }
        },"ftf");
        thread.start();
        try {
            thread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }



    public static void main(String[] args) throws InterruptedException {

    }
}
